home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / vcredit / vcrdtptn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  11.6 KB  |  386 lines

  1. /*
  2.  * Copyright (c) 1990, 1991 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/collab/vcrEdit/RCS/vcrEditOptions.c,v 0.25 92/06/15 14:37:13 drapeau Exp Locker: drapeau $ */
  25. /* $Log:    vcrEditOptions.c,v $
  26.  * Revision 0.25  92/06/15  14:37:13  drapeau
  27.  * Minor change, removed declaration of variable "chosenHost[]" since it is
  28.  * already declared in vcrEdit.h.
  29.  * 
  30.  * Revision 0.24  92/05/14  00:04:16  drapeau
  31.  * * Modified SetPlayer() function: it is no longer called when the
  32.  *   author chooses a player model (the interface was confusing).  Now
  33.  *   it is called only when a new button, labelled "Set Player", is
  34.  *   pressed.
  35.  * * Removed the function "SetPort()" since it is no longer needed, due
  36.  *   to the addition of the "Set Player" button.
  37.  * 
  38.  * Revision 0.23  91/09/29  16:10:35  lim
  39.  * 1. Removed mySerialPort, because we have additional field in
  40.  * port setting ("Default").
  41.  * 2. If player initialization fails in any way or is terminated,
  42.  * player setting is reset to "None".
  43.  * 3. If player initialization fails (NULL video object returned)
  44.  * the user will be notified to check player/serial line.
  45.  * 
  46.  * Revision 0.22  91/09/26  12:33:15  lim
  47.  * Changed 'host' to 'chosenHost' and 'chosenHost' is
  48.  * made global.
  49.  * 
  50.  * Revision 0.21  91/09/03  10:33:14  lim
  51.  * Checked for valid Sender & Receiver before disconnecting in SetNetworkHost.
  52.  * 
  53.  * Revision 0.20  91/08/30  15:15:12  lim
  54.  * Changed error message for no sender.
  55.  * 
  56.  * Revision 0.19  91/08/29  12:12:56  lim
  57.  * Added 'Defaults' to serial port.
  58.  * 
  59.  * Revision 0.18  91/08/28  12:52:35  lim
  60.  * 1. Added SetPreSearch() function, which allows user to choose if
  61.  * presearching should be done when performing on the TimeLine.
  62.  * 
  63.  * Revision 0.17  91/08/27  11:12:52  lim
  64.  * Done button also calls SetNetworkHost(), in case the user did not
  65.  * hit return when he typed in the network host name.
  66.  * 
  67.  * Revision 0.16  91/08/24  18:00:08  lim
  68.  * Implemented PrintDiagnostics. With command line flag '-d', the 
  69.  * app will launch such that it prints all diag messages.
  70.  * 
  71.  * Revision 0.15  91/08/21  10:52:30  lim
  72.  * *** empty log message ***
  73.  * 
  74.  * Revision 0.14  91/08/21  10:44:29  lim
  75.  * Fixed bug about serial port setting. Now, 'mySerialPort' will be
  76.  * set if the video object has not yet been initialized so that only
  77.  * upon initialization will SetSerialLine be called.
  78.  * This setting overrides both the ~/.Xdefaults setting AND the setting
  79.  * coded in the video library.
  80.  * 
  81.  * Revision 0.13  91/08/20  15:21:52  lim
  82.  * currTape is reset to "NULL" if we switch serial ports, because the
  83.  * device is potentially a different one, and therefore what used to be in
  84.  * the old device will no longer be what is in the new device.
  85.  * 
  86.  * Revision 0.12  91/08/16  12:34:29  lim
  87.  * 1. Change serial port setting when setting up driver.
  88.  * 2. Added optionsNetworkHost, which allows users to register with a
  89.  *    PortManager after launching app.
  90.  * 3. Info button moved here.
  91.  * 
  92.  * Revision 0.11  91/08/08  16:33:52  lim
  93.  * 1. Added instance pointer to each public videoObject function call.
  94.  * 2. Able to choose device to use vcrEdit with, using SetPlayer().
  95.  * 
  96.  * Revision 0.10  91/07/16  16:17:10  lim
  97.  * Initial revision.
  98.  *  */
  99.  
  100. #include "vcrEdit.h"
  101. static char optrcsid[] = "$Header: /Source/Media/collab/vcrEdit/RCS/vcrEditOptions.c,v 0.25 92/06/15 14:37:13 drapeau Exp Locker: drapeau $";
  102. VideoObject* myVideo;                            /* Current video Object */
  103.  
  104. /*     OPTIONS FOR CONTROLLING DISPLAY, SEARCH MODE, AUDIO (POPUP WINDOW 1)     */
  105.  
  106. /*
  107.  * Notify callback function for `optionsPlayerStg'.
  108.  */
  109. void SetPlayer(Panel_item item, Event *event)
  110. {
  111.   int        maxSpeed;
  112.   int        choice;
  113.   int        portSelection;
  114.   int        value;
  115.   char        chosenPlayerMsg[27+MaxNameLength];
  116.   char        chosenPortMsg[29];
  117.   char*        playPort;
  118.   Display*    display;
  119.   
  120.   value = xv_get(vcrEdit_optionsPopup->optionsPlayerStg, PANEL_VALUE); /* Determine currently-selected player, if any */
  121.   if (value == 0)                            /* Chose "None" => Return immediately */
  122.     return;
  123.   sprintf(chosenPlayerMsg, "You have chosen the %s player", 
  124.       allDevices[value-1]);
  125.   portSelection = (int) xv_get(vcrEdit_optionsPopup->port,
  126.                    PANEL_VALUE);
  127.   switch (portSelection)
  128.   {
  129.    case 0:
  130.     strcpy(chosenPortMsg, "and the default serial port.");
  131.     break;
  132.    case 1:
  133.     strcpy(chosenPortMsg, "and serial port A.");
  134.     break;
  135.    case 2:
  136.     strcpy(chosenPortMsg, "and serial port B.");
  137.     break;
  138.   }
  139.   choice = notice_prompt(vcrEdit_optionsPopup->optionsPopup,        /* Let user confirm player and serial port */
  140.              NULL, 
  141.              NOTICE_MESSAGE_STRINGS, chosenPlayerMsg,
  142.              chosenPortMsg,
  143.              "Please confirm player and",
  144.              "serial port selections.",
  145.              NULL,
  146.              NOTICE_BUTTON_YES, "Cancel",
  147.              NOTICE_BUTTON_NO, "OK", 
  148.              NULL);
  149.   
  150.   if (choice == NOTICE_YES)
  151.   {
  152.     xv_set(vcrEdit_optionsPopup->optionsPlayerStg, PANEL_VALUE, 0, NULL); /* Set player back to "None" */
  153.     return;
  154.   }
  155.   strcpy(deviceName, allDevices[value-1]);                /* The 0th item is "None" */
  156.   switch (portSelection)
  157.   {
  158.    case 0:
  159.     myVideo = DevInit(deviceName, NULL);
  160.     break;
  161.    case 1:
  162.     myVideo = DevInit(deviceName, "/dev/ttya");
  163.     break;
  164.    case 2:
  165.     myVideo = DevInit(deviceName, "/dev/ttyb");
  166.     break;
  167.   }
  168.   if (myVideo)
  169.   {
  170.     maxSpeed = GetDeviceMaxSpeed(myVideo);                /* Get max speed for current device */
  171.     xv_set(vcrEdit_window1->speedSlider,                /* Set slider values to correspond exactly to the ... */
  172.        PANEL_MIN_VALUE, -(maxSpeed),                /* ... maximum number of frames per second the player ... */
  173.        PANEL_MAX_VALUE, maxSpeed,                    /* ... can play */
  174.        NULL);
  175.     DevSetDefaults(myVideo, 3, 0, 0, 0);                /* Set device to default settings */
  176.     if (portSelection == 0)
  177.     {
  178.       display = (Display*) xv_get(vcrEdit_window1->window1, XV_DISPLAY); /* Put serial port on options panel */
  179.       playPort = XGetDefault(display, deviceName, "serialPort");
  180.       if (playPort == NULL)
  181.       {
  182.     if ((strcmp(myVideo->DevConfig->serialPort, "/dev/ttya") == 0) || 
  183.         (strcmp(myVideo->DevConfig->serialPort, "na") == 0))    /* Defaults to /dev/ttya */
  184.       xv_set(vcrEdit_optionsPopup->port, PANEL_VALUE, 1, NULL); 
  185.     else 
  186.       if (strcmp(myVideo->DevConfig->serialPort, "/dev/ttyb") == 0)
  187.         xv_set(vcrEdit_optionsPopup->port, PANEL_VALUE, 2, NULL); 
  188.       }
  189.       else
  190.     if (strcmp(playPort, "/dev/ttya") == 0)
  191.       xv_set(vcrEdit_optionsPopup->port, PANEL_VALUE, 1, NULL); 
  192.     else
  193.       xv_set(vcrEdit_optionsPopup->port, PANEL_VALUE, 2, NULL); 
  194.     }
  195.   }
  196.   else
  197.   {
  198.     notice_prompt(vcrEdit_optionsPopup->optionsPopup,            /* Player has not responded */
  199.           NULL, 
  200.           NOTICE_MESSAGE_STRINGS, "The player has failed to respond.", " ",
  201.           "Please check that :",
  202.           "1. You have chosen the correct player.                             ",
  203.           "2. The player is connected at the serial port you selected.",
  204.           "3. The baud rate and other player attributes are correct.  ",
  205.           "4. The player is not busy.                                                 ",
  206.           " ",
  207.           "and try again.",
  208.           NULL,
  209.           NOTICE_BUTTON, "OK", 100,
  210.           NULL);
  211.     xv_set(vcrEdit_optionsPopup->optionsPlayerStg, PANEL_VALUE, 0, NULL); /* Set player back to "None" */
  212.   }
  213.   /* gxv_start_connections DO NOT EDIT THIS SECTION */
  214.   
  215.   /* gxv_end_connections */
  216. }                                    /* end function SetPlayer */
  217.  
  218.  
  219. /*
  220.  * Notify callback function for `optionsNetworkHost'.
  221.  */
  222. void
  223.   SetNetworkHost(Panel_item item, Event* event)
  224. {
  225.   char* tmp;
  226.   Port senderPort;
  227.   char diagMsg[30];
  228.   
  229.   tmp = (char *) xv_get(item, PANEL_VALUE);
  230.   if ((strlen(tmp) == 0) || (chosenHost && (strcmp(tmp, chosenHost) == 0)))
  231.     return;
  232.   else
  233.     strcpy(chosenHost, tmp);
  234.   
  235.   if (sender && receiver)
  236.     SenderDisconnectFromPortMgr(sender,&(receiver->receivePort));
  237.   
  238.   sender = NULL;
  239.   receiver = NULL;
  240.   
  241.   senderPort.hostName = chosenHost;
  242.   senderPort.portNumber = PortMgrPortNumber;
  243.   sender = NewSender(&senderPort);
  244.   if (!sender)
  245.   {
  246.     DisplayError("Host name is not valid", "Or Port Manager is not active");
  247.     return;
  248.   }
  249.   receiver = NewReceiver(sender, "vcrEdit", receiverPort);
  250.   sprintf(diagMsg, "Listening on port %d.\n", receiver->transport->xp_port);
  251.   PrintDiagnostics(diagMsg);
  252.   
  253.   return;
  254. }                                    /* end function SetNetworkHost */
  255.  
  256.  
  257. /*
  258.  * Notify callback function for `optionsInfoButton'.
  259.  */
  260. void
  261. Info(item, event)
  262.         Panel_item      item;
  263.         Event           *event;
  264. {
  265.   xv_set(vcrEdit_infoPopup->infoPopup, FRAME_CMD_PUSHPIN_IN, TRUE, NULL);
  266.   xv_set(vcrEdit_infoPopup->infoPopup, XV_SHOW, TRUE, NULL);
  267. }
  268.  
  269.  
  270. /*
  271.  * Notify callback function for `optionsVideoStg'.
  272.  */
  273.  
  274. void
  275. VideoSelect(item, value, event)
  276.     Panel_item    item;
  277.     int        value;
  278.     Event        *event;
  279. {
  280.   DevSetVideo(myVideo, value);
  281. }
  282.  
  283. /*
  284.  * Notify callback function for `optionsMutedScreen'.
  285.  */
  286. void
  287. ScreenSelect(item, value, event)
  288.     Panel_item    item;
  289.     int        value;
  290.     Event        *event;
  291. {
  292.   int brightness;
  293.  
  294.   if (strcmp(deviceName, "NEC") != 0)
  295.     return;
  296.   
  297.  brightness = xv_get(vcrEdit_optionsPopup->optionsBrightStg, 
  298.               PANEL_VALUE);
  299.   NECScreenSelect(myVideo, value, brightness);
  300. }
  301.  
  302. /*
  303.  * Notify callback function for `optionsBrightStg'.
  304.  */
  305. void
  306. BrightSelect(item, value, event)
  307.         Panel_item    item;
  308.     int        value;
  309.     Event        *event;
  310. {
  311.   int color;
  312.  
  313.   if (strcmp(deviceName, "NEC") != 0)
  314.     return;
  315.  
  316.   color = xv_get(vcrEdit_optionsPopup->optionsMutedScreen,
  317.              PANEL_VALUE) +1;
  318.   NECScreenSelect(myVideo, color, value);
  319. }
  320.  
  321.  
  322. /*
  323.  * Notify callback function for `optionsAudioStg'.
  324.  * Select audio setting 
  325.  */
  326. void
  327. AudioSelect(item, value, event)
  328. Panel_item    item;
  329. int        value;
  330. Event        *event;
  331. {
  332.   switch (value) 
  333.   {
  334.    case 0 : xv_set(vcrEdit_window1->window1, FRAME_RIGHT_FOOTER, 
  335.            "Audio : Mute", NULL);
  336.     break;
  337.    case 1 : xv_set(vcrEdit_window1->window1, FRAME_RIGHT_FOOTER, 
  338.            "Audio : Left", NULL);
  339.     break;
  340.    case 2 : xv_set(vcrEdit_window1->window1, FRAME_RIGHT_FOOTER, 
  341.            "Audio : Right", NULL);
  342.     break;
  343.    case 3 : xv_set(vcrEdit_window1->window1, FRAME_RIGHT_FOOTER, 
  344.            "Audio : Stereo", NULL);
  345.     break;
  346.    case 4 : xv_set(vcrEdit_window1->window1, FRAME_RIGHT_FOOTER,
  347.            "Audio : Normal", NULL);
  348.     break;
  349.   }
  350.   DevSetAudio(myVideo, value);
  351.   
  352. }
  353.  
  354.  
  355. /*
  356.  * Notify callback function for `optionsPreSearch'.
  357.  */
  358. void
  359. SetPreSearch(item, value, event)
  360.     Panel_item    item;
  361.     int        value;
  362.     Event        *event;
  363. {
  364.   if (value)                                /* Yes, presearch! */
  365.     preSearch = Yes;
  366.   else
  367.     preSearch = No;
  368. }
  369.  
  370.  
  371. /*
  372.  * Notify callback function for `optionsDoneButton'.
  373.  * Calls SetNetworkHost
  374.  * To close the options popup window
  375.  */
  376. void
  377. Done(item, event)
  378.         Panel_item      item;
  379.         Event           *event;
  380. {
  381.   SetNetworkHost(vcrEdit_optionsPopup->optionsNetworkHost, NULL);
  382.   xv_set(vcrEdit_optionsPopup->optionsPopup, FRAME_CMD_PUSHPIN_IN, FALSE, NULL);
  383.   xv_set(vcrEdit_optionsPopup->optionsPopup, XV_SHOW, FALSE, NULL);
  384. }
  385.  
  386.